package com.itheima.d1_staticdemo;

import java.util.Random;

public class VerifyTool {
    public static String CreateCode(int n){
        String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        String code="";
        Random r = new Random();
        //生产一个n位的验证码
        for (int i = 0; i < n; i++) {
            //生成随机索引
            int index = r.nextInt(chars.length());
            //提取索引的数字并且拼接
            code += chars.charAt(index);
        }
        return code;
    }
}
